//
//  MDHomeViewController.swift
//  麦兜直播
    //
//  Created by yeqingyu on 16/9/25.
//  Copyright © 2016年 yeqingyu. All rights reserved.
//

import UIKit

class MDHomeViewController: UIViewController {
    
    fileprivate lazy var chiledVcArr:[UIViewController] = {
        var arr = [UIViewController]()
        let recommendVc = MDRecommendViewController()
        arr.append(recommendVc)
        
        for index in 0...2{
         let viewVc = UIViewController()
            if (index%2==0){
              viewVc.view.backgroundColor = UIColor.red
            }else{
              viewVc.view.backgroundColor = UIColor.blue
            }
          arr.append(viewVc)
        }
        
        return arr;
    }()
    
    fileprivate lazy var titleView:MDSlideTitleView = {
        let frame = CGRect(x: 0, y: naviBarHeight, width: screenWidth, height:titleHeight)
        let titles = ["推荐", "游戏", "娱乐", "趣玩"]
        let titleView = MDSlideTitleView(frame: frame, titles: titles)
        titleView.delegate = self
        return titleView
    }()
    
    
    fileprivate lazy var contentView:MDContentView = {
        let frame =  CGRect(x: 0, y: naviBarHeight+titleHeight, width: screenWidth, height: screenHeight-(naviBarHeight+titleHeight+tabarHeight))
        let contentView = MDContentView(frame: frame, chiledControllers: self.chiledVcArr, parentController: self)
        contentView.delegate = self
        return contentView
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
          title = "首页"
        setUpHeadTitleAndContentView()
    }
    
}


extension MDHomeViewController{
    fileprivate func setUpHeadTitleAndContentView(){

        view.addSubview(titleView)
        view.addSubview(contentView)
        
    }
}


extension MDHomeViewController:MDSlideTitleViewDelegate,MDContentViewDelegate{

    func MDSlideTitleViewDidClickTitle(currentIndex: Int) {        
        contentView.scrollToCurrrentPage(index: currentIndex)
    }
    
    
    func MDContentViewDidMove(startPoint: CGPoint, offSet: CGPoint) {
           titleView.setUpLineOffSetWithAnimation(startPoint:startPoint,offset: offSet)
    }
}
